<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 商品品牌类
 * 
 * @author  : $Author: spike $
 * @date    : $Date: 2014-07-04 11:50:20 +0800 (五, 2014-07-04) $
 * @version : $Id: trend_model.php 114 2014-07-04 03:50:20Z spike $
 * @rev     : $Revision: 114 $
 */
class Trend_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    // --------------------------------------------------------------------
    
    /**
     * [获得一个市场动态]
     * @param  [string]     $trend_id
     * @param  [bool]       $enable        [是否排除"关闭状态"]
     * @return [array/false]
     */
    public function get_trend($trend_id, $enable = TRUE)
    {
        if( ! validate($trend_id, 'TREND_ID') )
        {
            $this->set_error("获取市场动态失败：编码格式不正确。[{$trend_id}]");
            return FALSE;
        }
        
        $where = array(
            'trend_id'  => $trend_id,
            'is_delete' => UNDELETED,
        );
        if($enable === TRUE)
        {
            $where['status'] = TREND_STATUS_ON;
        }

        $this->load->dao('Trend_dao');
        $trend = $this->Trend_dao->get_one($where);
        if( ! $trend)
        {
            $this->set_error("获取市场动态失败：无法找到市场动态[{$trend_id}]。");
            return FALSE;
        }
        $trend['desc'] = htmlspecialchars_decode("&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/14043817314728.jpg&amp;quot;src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/14043817314728.jpg&amp;quot; height=&amp;quot;358&amp;quot; width=&amp;quot;333&amp;quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;hr align=&amp;quot;center&amp;quot;/&amp;gt;&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/14043817671294.jpg&amp;quot;src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/14043817671294.jpg&amp;quot; height=&amp;quot;399&amp;quot; width=&amp;quot;300&amp;quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;hr align=&amp;quot;center&amp;quot;/&amp;gt;&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/14043817758633.jpg&amp;quot;src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/14043817758633.jpg&amp;quot; height=&amp;quot;400&amp;quot; width=&amp;quot;300&amp;quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;hr/&amp;gt;&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/1404381785363.jpg&amp;quot;src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/1404381785363.jpg&amp;quot; height=&amp;quot;400&amp;quot; width=&amp;quot;300&amp;quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;hr/&amp;gt;&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/14043817969965.jpg&amp;quot;src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/14043817969965.jpg&amp;quot; height=&amp;quot;399&amp;quot; width=&amp;quot;300&amp;quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;hr/&amp;gt;&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/1404381809464.jpg&amp;quot;src=&amp;quot;http://bkd.tcfschina.com/theme/default/js/jquery/jquery-ueditor-mini/php/upload/20140703/1404381809464.jpg&amp;quot; height=&amp;quot;263&amp;quot; width=&amp;quot;350&amp;quot;/&amp;gt;&amp;lt;/p&amp;gt;");
        var_dump($trend['desc']);
        die;
        return $trend;
    }

    // --------------------------------------------------------------------
    
    /**
     * [分页浏览]
     * @param  [array]  $params  [条件]
     * @param  [int]    $page    [当前页]
     * @param  [int]    $size    [页数，只允许app_config中"pagesize"的值]
     * @param  [string] $orderby [排序]
     * @return [array]
     */
    public function browse_trend($params, $page = NULL, $size = NULL, $orderby = '`create_time` DESC')
    {
        $where = array('status'=>TREND_STATUS_ON);

        $pagesize = $this->config->item('pagesize');
        $size     = isset($pagesize[$size]) ? $size : 12;
        $offset   = intval(($page-1)*$size) > 0 ? intval(($page-1)*$size) : 0;
        $total    = 0;

        $this->load->dao('Trend_dao');
        $data = $this->Trend_dao->get(
            $where, 
            '*', 
            $orderby, 
            $size, 
            $offset, 
            TRUE, 
            $total
        );
        return array(
            'size' => $size,
            'data' => $data,
            'total'=> $total,
        );
    }

}